//
// Created by dddgzc on 2025/1/23.
//

#ifndef ATLAS_H
#define ATLAS_H

#include <vector>
#include <string>
#include <SDL_image.h>

extern SDL_Renderer* mainRenderer;

class Atlas {
public:
    Atlas() = default;
    ~Atlas() = default;
    /**
     *
     * @param pathTemplate 路径模板
     * @param num 图片数量
     */
    void loadFromFile(const char* pathTemplate, int num);

    void loadFromFileFlip(const char* pathTemplate, int num);

    void clearImages();

    SDL_Texture* getImage(int index) const;

    int getSize() const;

    void addImage(SDL_Texture* texture);

    // 资源释放
    void freeImages();

private:
    std::vector<SDL_Texture*> images;
};

inline void Atlas::freeImages() {
    for (int i = 0; i < images.size(); i++) {
        SDL_DestroyTexture(images[i]);
    }
}


#endif //ATLAS_H
